<div class="deploy_form">
    <div class="modal-header ">
        <button aria-hidden="true" type="button " class="close close-x" data-dismiss="modal"></button>
        <h3>新建子网</h3>
    </div>
    <div class="modal-body">
        <div  class="form-horizontal" >
            <div class="control-group">
                <label class="control-label">子网命名<span class="required">*</span></label>
                <div class="controls">
                    <input type="text" name="subnet_name" id="subnet_name" value="<?php echo $subnet_name;?>" class="span6 m-wrap">
                </div>
            </div>

            <div class="control-group">
                <label class="control-label">子网网段<span class="required">*</span></label>
                <div class="controls">
                    <div class="input-prepend input-append">
                        <span class="add-on">192.</span><span class="add-on">168.</span>
                        <input type="text" id="vpc_add_subnet_network" name="network" class="span2 m-wrap " value="<?php echo $network;?>">
                        <span class="add-on">.0 </span><span class="add-on">/</span>
                        <span class="add-on">255.</span><span class="add-on">255.</span><span class="add-on">255.</span>
                        <span class="add-on">0</span>
                    </div>
                </div>
            </div>
            <input name="app_id" type="hidden" value="<?php echo $app_id;?>">
            <input name="vpc_name" type="hidden"  value="<?php echo $vpc_name;?>">
            <input name="region" type="hidden"  value="<?php echo $region;?>">
            <div class="modal-footer ">
                <button aria-hidden="true" data-dismiss="modal" class="btn close"  onclick="trigger('close');">取消</button>

                <?php if(isset($edit)){ ?>
                <button aria-hidden="true" id="subnet_edit_submit_btn" class="btn green btn-primary " type="button" value="<?php echo $app_id;?>"><i class="icon-ok"></i>修改</button>
                <?php }else{ ?>
                <button aria-hidden="true" id="subnet_submit_btn"  value="<?php echo $app_id;?>" class="btn green btn-primary " type="button"><i class="icon-ok"></i>确认</button>
                <?php } ?>



            </div>
        </form>
            </div>
    </div>
</div>



<script>

    $(function(){
        //check network exists
        $("input[name='network']").change(function(){
            var ef=$(this);
            var app_id=ef.parent().parent().parent().parent().find($("input[name=app_id]")).val();
            $.ajax({
                url: 'index.php?route=deploy/subnet/check_subnet_address',
                cache: false,
                dataType: 'json',
                type: 'POST',
                data: {
                    app_id: app_id,
                    subnetaddr: $(this).val(),
                    vpc_name: $("#subnet_form-"+app_id+" input[name=vpc_name]").val()
                },
                error: function() {
                },
                beforeSend: function() {
                    ef.after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
                },
                complete: function() {
                    $('.wait').remove();
                },
                success: function(json) {
                    if(json['result']=='success'){
                        ef.removeClass("success");
                        ef.removeClass("error");
                        ef.addClass("success");
                    }else{
                        ef.removeClass("success");
                        ef.removeClass("error");
                        ef.addClass("error");
                    }
                }
            });
        });
        //check subnet name exists
        $("input[name='subnet_name']").change(function(){
            var ef=$(this);
            var app_id=ef.parent().parent().parent().find($("input[name=app_id]")).val();
            $.ajax({
                url: 'index.php?route=deploy/subnet/check_subnet_name_exist',
                cache: false,
                dataType: 'json',
                type: 'POST',
                data: {
                    app_id:  app_id,
                    subnet_name: $(this).val(),
                    vpc_name: $("#subnet_form-"+app_id+" input[name=vpc_name]").val()
                },
                error: function() {
                },
                beforeSend: function() {
                    ef.after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
                },
                complete: function() {
                    $('.wait').remove();
                },
                success: function(json) {
                    if(json['result']=='success'){
                        ef.removeClass();
                        ef.addClass("success");
                    }else{
                        ef.removeClass();
                        ef.addClass("error");
                    }
                }
            });
        });
    })
</script>